home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / setup / vbnet / 23 web forms and controls / firstwebforms / htmlcontrolsform.aspx.vb < prev    next >
Encoding:
Text File  |  2002-03-17  |  1.9 KB  |  49 lines

  1. ' This form demonstrates how to upload files to a server
  2.  
  3. Public Class HtmlControlsForm
  4.     Inherits System.Web.UI.Page
  5.     Protected WithEvents File1 As System.Web.UI.HtmlControls.HtmlInputFile
  6.     Protected WithEvents DIV1 As System.Web.UI.HtmlControls.HtmlGenericControl
  7.     Protected WithEvents Button1 As System.Web.UI.HtmlControls.HtmlInputButton
  8.  
  9. #Region " Web Form Designer Generated Code "
  10.  
  11.     'This call is required by the Web Form Designer.
  12.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  13.  
  14.     End Sub
  15.  
  16.     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
  17.         'CODEGEN: This method call is required by the Web Form Designer
  18.         'Do not modify it using the code editor.
  19.         InitializeComponent()
  20.     End Sub
  21.  
  22. #End Region
  23.  
  24.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  25.         'Put user code to initialize the page here
  26.     End Sub
  27.  
  28.     ' this procedure fires when the form is submitted
  29.     ' it reads and displays data about the file that has been uploaded
  30.     ' and saves the file itself to c:\file.dat
  31.  
  32.     Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ServerClick
  33.         Dim msg As String
  34.         If Not File1.PostedFile Is Nothing Then
  35.             msg = "<b>Filename = </b>" & File1.PostedFile.FileName & "<br>"
  36.             msg &= "<b>ContentLength = </b>" & File1.PostedFile.ContentLength & "<br>"
  37.             msg &= "<b>ContentType = </b>" & File1.PostedFile.ContentType & "<br>"
  38.             File1.PostedFile.SaveAs("C:\file.dat")
  39.             msg &= "File has been saved on the server"
  40.         Else
  41.             msg = "No file has been posted"
  42.         End If
  43.  
  44.         ' display information in the Div1 control.
  45.         DIV1.InnerHtml = msg
  46.     End Sub
  47.  
  48. End Class
  49.